Add Kitty Keyboard Protocol support (Phase 1 + Phase 2 start) - #4810
Merged
Conversation
Refactor terminal attachment checks into Driver.IsAttachedToTerminal, which now handles platform-specific logic and honors the DisableRealDriverIO environment variable for test environments. Updated all drivers to use this unified method, and simplified AnsiTerminalHelper to delegate to it. Moved relevant P/Invoke code to Driver. Added comprehensive unit tests for all drivers and the environment variable gating. Introduced test.runsettings and Directory.Build.props changes to ensure DisableRealDriverIO is set during test runs, improving testability and consistency of degraded mode detection.
- Reformat method calls and declarations for readability - Use C# pattern matching and switch expressions - Refactor OutputBase properties to auto-properties - Convert trivial methods to expression-bodied members - Fix logic in OutputBase.Write, UnixInput init, and WindowsOutput error handling - Remove AnsiTerminalHelper.IsAttachedToTerminal and related test - Use explicit types for clarity - Reformat and clarify P/Invoke signatures - Update .DotSettings and documentation comments - Improve maintainability and correctness throughout drivers
9 tasks
tig
marked this pull request as draft
March 8, 2026 20:41
Add IsAttachedToTerminal to OutputBase and update all output drivers (AnsiOutput, NetOutput, UnixOutput, WindowsOutput) to check this property before performing terminal I/O. When not attached to a real terminal, output methods now return early, perform no-ops, or return default values. Constructors log lifecycle messages if no terminal is attached. Tests updated to verify no escape sequences or state changes occur in these scenarios. This prevents errors and unwanted output in redirected or non-interactive environments.
Move IsAttachedToTerminal checks after base logic in Output classes to ensure base behavior is always executed. Streamline and centralize terminal checks, reduce code duplication, and improve consistency across AnsiOutput, NetOutput, UnixOutput, and WindowsOutput. Adjust platform-specific logic and early returns for better maintainability and correct output buffer handling.
Centralize IsAttachedToTerminal logic in InputImpl<T> and update all input classes (AnsiInput, NetInput, UnixInput, WindowsInput) to use it for degraded mode detection and logging. Simplify AnsiOutput by removing redundant terminal checks and updating Kitty keyboard methods. Refactor MainLoopCoordinatorTests for modern C# syntax, restoring and improving Kitty protocol and error handling tests. Improves clarity, maintainability, and test reliability.
Refactor terminal attachment checks into Driver.IsAttachedToTerminal, which now handles platform-specific logic and honors the DisableRealDriverIO environment variable for test environments. Updated all drivers to use this unified method, and simplified AnsiTerminalHelper to delegate to it. Moved relevant P/Invoke code to Driver. Added comprehensive unit tests for all drivers and the environment variable gating. Introduced test.runsettings and Directory.Build.props changes to ensure DisableRealDriverIO is set during test runs, improving testability and consistency of degraded mode detection.
- Reformat method calls and declarations for readability - Use C# pattern matching and switch expressions - Refactor OutputBase properties to auto-properties - Convert trivial methods to expression-bodied members - Fix logic in OutputBase.Write, UnixInput init, and WindowsOutput error handling - Remove AnsiTerminalHelper.IsAttachedToTerminal and related test - Use explicit types for clarity - Reformat and clarify P/Invoke signatures - Update .DotSettings and documentation comments - Improve maintainability and correctness throughout drivers
Add IsAttachedToTerminal to OutputBase and update all output drivers (AnsiOutput, NetOutput, UnixOutput, WindowsOutput) to check this property before performing terminal I/O. When not attached to a real terminal, output methods now return early, perform no-ops, or return default values. Constructors log lifecycle messages if no terminal is attached. Tests updated to verify no escape sequences or state changes occur in these scenarios. This prevents errors and unwanted output in redirected or non-interactive environments.
Move IsAttachedToTerminal checks after base logic in Output classes to ensure base behavior is always executed. Streamline and centralize terminal checks, reduce code duplication, and improve consistency across AnsiOutput, NetOutput, UnixOutput, and WindowsOutput. Adjust platform-specific logic and early returns for better maintainability and correct output buffer handling.
Centralize IsAttachedToTerminal logic in InputImpl<T> and update all input classes (AnsiInput, NetInput, UnixInput, WindowsInput) to use it for degraded mode detection and logging. Simplify AnsiOutput by removing redundant terminal checks and updating Kitty keyboard methods. Refactor MainLoopCoordinatorTests for modern C# syntax, restoring and improving Kitty protocol and error handling tests. Improves clarity, maintainability, and test reliability.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Moved and duplicated tests for DisableRealDriverIO env var and Driver.IsAttachedToTerminal from DriverTests to IntegrationTests. Also refactored test output usage to use the output parameter directly. This ensures environment variable handling is verified in both test contexts.
# Conflicts: # Terminal.Gui/Drivers/AnsiDriver/AnsiInput.cs # Terminal.Gui/Drivers/AnsiDriver/AnsiOutput.cs # Terminal.Gui/Drivers/DotNetDriver/NetInput.cs # Terminal.Gui/Drivers/UnixDriver/UnixInput.cs # Terminal.Gui/Drivers/WindowsDriver/WindowsInput.cs # Terminal.Gui/Drivers/WindowsDriver/WindowsOutput.cs # Tests/UnitTests/Application/MainLoopCoordinatorTests.cs # Tests/UnitTestsParallelizable/Application/MainLoopCoordinatorTests.cs # Tests/UnitTestsParallelizable/Drivers/Ansi/AnsiTerminalHelperTests.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Refactored tracing calls in input classes to remove unnecessary string interpolation and ensure consistent usage of Trace.Lifecycle. Added early return in AnsiOutput for degraded platforms. Simplified window size comparison in WindowsOutput. Cleaned up imports and removed redundant code in test files, including refactoring test output usage for clarity.
Remove commented-out logging/tracing statements from AnsiInput, AnsiOutput, and WindowsOutput for cleaner code. Refactor AnsiOutput to use an auto-property for KittyKeyboardEnabledFlags and update related logic. Add a descriptive trace message to AnsiOutput.Dispose(). Replace commented exception in WindowsOutput with a trace log on resize failure. Minor doc and formatting improvements in NetInput.
AnsiOutput.EnableKittyKeyboard now skips enablement when the platform is Degraded, making it a no-op in such environments. Updated related test to focus on detection rather than enable/disable, renamed the test for clarity, and adjusted assertions to match the new behavior. Removed checks for escape sequences that are not emitted in degraded mode.
Adds detailed implementation steps for Phase 2 (Rich Keyboard Event Model) including Key.EventType, KeyUp pipeline, Windows/kitty driver integration, standalone modifier events, and view-level keyboard updates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5 tasks
This was referenced May 1, 2026
This was referenced May 11, 2026
This was referenced May 21, 2026
This was referenced Jun 1, 2026
This was referenced Jun 15, 2026
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
uparser, and compatibility mapping into the currentKeymodelKeyUp,KeyEventType, standalone modifier events)v2_developand resolved all conflictsRelates to #4809
What's included
Phase 1 — Compatibility plumbing
EscSeqUtilsKittyKeyboardProtocolDetectorwith structured resultsMainLoopCoordinatorAnsiOutputenable/disable lifecycle with degraded mode safetyKittyKeyboardPatternparser (checked before generic CSI patterns)Merge resolution
v2_developintegrationTraceambiguity (System.Diagnostics.TracevsTerminal.Gui.Tracing.Trace)using Terminal.Gui.Tracingpattern and primary constructor styleTest plan
dotnet build --no-restorepassesdotnet test --project Tests/UnitTestsParallelizable --no-build— all passdotnet test --project Tests/UnitTests --no-build— all pass🤖 Generated with Claude Code